#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

# Entradas
with display_block('Variáveis'):
    n_iter = 0
    Nmax = 55
    while True:
        n_iter += 1

        # Sorteia os raios
        n = oneof(1, 2, 3)
        if n == 1:
            a = (One * oneof(1, 2, 3, 4, 5, 6, 8, 9, 12)) / oneof(1, 2, 3, 4)
            b = (One * oneof(1, 2, 3, 4, 5, 6, 8, 9, 12)) / oneof(1, 2, 3, 4)
        elif n == 2:
            a = (One * oneof(1, 2, 3, 4, 5)) / oneof(1, 2)
            b = (One * oneof(1, 2, 3, 4, 5)) / oneof(1, 2)
        else:
            a = (One * oneof(1, 2, 3))
            b = (One * oneof(1, 2, 3))
        a, b = min(a, b), max(a, b)
        if a == b:
            continue
        rho_expon = rho ** n

        # Valor correta
        correta = together(2 * pi * (r ** (3 - n)).integrate([r, a, b]))

        # Sem jacobiano
        jacob = together(4 * pi * sp.logcombine((r ** (1 - n)).integrate([r, a, b])))

        # Integrou de 0 a b em rho
        erroRho = together(2 * pi * (r ** (3 - n)).integrate([r, 0, b]))

        # Esqueceu a densidade
        densidade = Four / 3 * pi * (b ** 3 - a ** 2)

        # Metade da correta
        corretaHalf = correta / 2

        _answers = [ correta, jacob, erroRho, densidade, corretaHalf ]

        # Distratores
        _dis = []
        while len(_dis) < 2:
            d = (oneof(*_answers) * oneof(2, 3, 4, 5, 6)) / oneof(2, 3, 4, 5, 6)
            if d not in _answers:
                _dis.append(d)
                _answers.append(d)
        distr1, distr2 = _dis

        _cont = False
        for aa in _answers:
            _num, _den = (aa / pi).as_numer_denom()
            if _den > Nmax or _num > Nmax:
                _cont = True
        if _cont:
            continue

        if len(_answers) == len(set(_answers)):
            break
